Skip to content

Conversation

@bendrucker
Copy link
Member

@bendrucker bendrucker commented Nov 26, 2025

Implements version update notifications similar to Terraform. When running tflint --version, users now see a notification if a newer version is available on GitHub Releases.

Changes

  • Adds versioncheck package that checks GitHub Releases API for latest version
  • Modifies --version command to display update notifications when newer version available
  • Adds --format json support to version command with structured output including update status
  • Supports TFLINT_DISABLE_VERSION_CHECK environment variable to opt out
  • Caches version check results for 48 hours in platform-specific cache directory

Implementation Details

Version checking happens asynchronously for text output (prints version immediately, shows update after plugins). JSON format performs synchronous check to ensure complete data in single output.

Results are cached in the OS cache directory (~/Library/Caches/tflint on macOS, ~/.cache/tflint on Linux) for 48 hours to minimize API calls.

The check uses GitHub's public API (60 req/hour unauthenticated) or GITHUB_TOKEN environment variable for higher rate limits (5000 req/hour).

Errors are logged but non-fatal - network timeouts or API failures don't break the version command.

JSON Output

JSON output includes update_check_enabled field to distinguish between disabled checking vs. no update available:

  • update_check_enabled: false → checking disabled via env var
  • update_check_enabled: true, update_available: false → no update or check failed
  • update_check_enabled: true, update_available: true → update available

Testing

Verified version checking against live GitHub API with both outdated and current versions. Added unit testing against the internals.

References

Closes #883

Implements version update notifications similar to Terraform's pattern.
When running tflint --version, users see a notification if a newer version
is available on GitHub Releases.

## Changes

- Adds `versioncheck` package that checks GitHub Releases API for latest version
- Modifies `--version` command to display update notifications when newer version available
- Adds `--format json` support to version command with structured output including update status
- Supports `TFLINT_DISABLE_VERSION_CHECK` environment variable to opt out
- Caches version check results for 48 hours in platform-specific cache directory

## Implementation Details

Version checking happens on every `--version` invocation with a 3-second timeout.
Results are cached in the OS cache directory (`~/Library/Caches/tflint` on macOS,
`~/.cache/tflint` on Linux) for 48 hours to minimize API calls.

The check uses GitHub's public API (60 req/hour unauthenticated) or `GITHUB_TOKEN`
environment variable for higher rate limits (5000 req/hour).

Errors are logged but non-fatal - network timeouts or API failures don't break
the version command.

## Testing

Verified version checking against live GitHub API with both outdated and current versions.
Cache behavior tested with 48-hour TTL validation. JSON output structure validated
for both text and JSON formats.

Closes #883
@bendrucker bendrucker changed the title feat: add version update notifications version: add update notifications Nov 26, 2025
@bendrucker bendrucker changed the title version: add update notifications version: add update notifications, json output Nov 26, 2025
@bendrucker bendrucker requested a review from Copilot November 26, 2025 21:45
Copilot finished reviewing on behalf of bendrucker November 26, 2025 21:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements version update notifications for TFLint, similar to Terraform's approach. When running tflint --version, users are notified if a newer version is available on GitHub Releases. The implementation includes JSON output support via --format json and can be disabled using the TFLINT_DISABLE_VERSION_CHECK environment variable.

Key changes:

  • Adds version checking with GitHub Releases API integration (60 req/hour unauthenticated, 5000 req/hour with GITHUB_TOKEN)
  • Implements 48-hour caching in platform-specific cache directories to minimize API calls
  • Adds JSON output format for version command with structured update information

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
versioncheck/github.go Implements GitHub API integration to fetch latest release version with optional authentication and rate limit handling
versioncheck/check.go Core version checking logic with caching support and version comparison
versioncheck/check_test.go Unit tests for Enabled() and compareVersions() functions
versioncheck/cache.go Cache management with 48-hour TTL using platform-specific cache directories
versioncheck/cache_test.go Unit tests for cache expiration logic
cmd/version.go Integrates version checking into --version command with text and JSON output formats
docs/user-guide/environment_variables.md Documents TFLINT_DISABLE_VERSION_CHECK environment variable

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Fix rate limit check in GitHub API error handling
- Remove misleading comment about error handling
- Add boundary checks in tests to prevent panics
- Expand test coverage for version comparison and environment variables
- Document GITHUB_TOKEN environment variable
- Make GitHub client testable with httptest
Addresses errcheck linter violation
@bendrucker bendrucker requested a review from Copilot November 27, 2025 17:38
Copilot finished reviewing on behalf of bendrucker November 27, 2025 17:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Add update_check_enabled field to JSON output for clarity
- Remove unused test variables in github_test.go
- Consolidate notification message for thread safety
- Make version check async for text format to improve responsiveness
@bendrucker bendrucker marked this pull request as ready for review November 29, 2025 03:32
@bendrucker bendrucker requested a review from wata727 November 29, 2025 03:32
Adds comprehensive integration tests that verify:
- Recursive mode populates modules array with per-directory plugins
- Top-level plugins field contains deduplicated plugins across all modules
- Deduplication works correctly (aws in root + module1 = 1 entry)
- Different plugins across modules are included (aws + google = 2 entries)
- Plugins are sorted by name, then version
- Non-recursive mode maintains backwards compatibility (no modules field)
- Text format output works correctly

Tests use real plugin downloads via --init to validate actual behavior.
@bendrucker bendrucker requested a review from wata727 December 4, 2025 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Inform users when a new version is available

3 participants